import listStatus from '../../../tabBar/public/js/way-list-status.js';
export default {
	data() {
		return {
			waybill_id: '',
			waybillDetail: {
				waybill_certificate: {
					delivery_certificate: "",
					delivery_certificate_date: "",
					delivery_certificate_p1: "",
					delivery_certificate_p1_date: "",
					depart_certificate: "",
					depart_certificate_date: "",
					depart_certificate_p1: "",
					depart_certificate_p1_date: "",
					depart_certificate_p2: "",
					depart_certificate_p2_date: "",
				},
			},
			in_type: 0, //1发货或分拨 2到站  11扫码-发货或分拨 21扫码-到站  3微信扫码 4搜索
		}
	},
	created() {

	},
	onLoad(options) {
		if (options && options.waybill_id) {
			this.waybill_id = options.waybill_id;
			//1发货或分拨 2到站  11扫码-发货或分拨 21扫码-到站 3微信扫码 4搜索
			this.in_type = options.in_type;
		} else {
			// var urlStr = "https://3plapidev1.chengxin56.net/weixinArrive/" +
			// 	"?waybill_type=1&waybill_sn=T12023100500002&waybill_id=162";
			const urlStr = decodeURIComponent(options.q); // 获取到二维码原始链接内容
			var waybill_id = this.$util.getQueryVariable('waybill_id', urlStr);
			//1发货或分拨 2到站  11小程序扫码-发货或分拨 21小程序扫码-到站  3微信扫码
			this.in_type = '3';
		}
	},
	onShow() {
		if (!this.check.isLogin()) {
			uni.navigateTo({
				url: "/pages/login/login/login"
			});
		} else {
			this.getDetailData();
		}
	},
	methods: {
		showAlertUI() {
			if (this.in_type == '21') {
				var isUpload = listStatus.getSelect(this.waybillDetail);
				if (!isUpload) {
					uni.showModal({
						title: '提示',
						content: '此运单不可上传到货凭证！',
						showCancel: false
					})
				}
			} else if (this.in_type == '11') {
				let level = uni.getStorageSync(this.preutils.accountLevel);
				if (level == 0) {
					if (this.waybillDetail.status != 500) {
						uni.showModal({
							title: '提示',
							content: '此运单不可上传分拨凭证！',
							showCancel: false
						})
					}
				} else {
					var isUpload = listStatus.getSelect(this.waybillDetail);
					if (!isUpload) {
						uni.showModal({
							title: '提示',
							content: '此运单不可上传发货凭证！',
							showCancel: false
						})
					}
				}
			} else {

			}
		},
		showDepartBtn() { //in_type 1发货或分拨 2到站  11扫码-发货或分拨 21扫码-到站
			let level = uni.getStorageSync(this.preutils.accountLevel);
			var isUpload = false;
			if (this.in_type == '1' || this.in_type == '11') {
				if (level == 2) {
					if (this.waybillDetail.status_p2 == 100) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else if (level == 1) {
					if (this.waybillDetail.status == 300) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else {
					isUpload = false;
				}
			} else if (this.in_type == '3' || this.in_type == '4') {
				if (level == 2) {
					if (this.waybillDetail.status_p2 == 100) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else if (level == 1) {
					if (this.waybillDetail.status == 300) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else {
					isUpload = false;
				}
			} else {
				isUpload = false;
			}
			return isUpload;
		},
		showDeliveryBtn() { //in_type 1发货或分拨 2到站  11扫码-发货或分拨 21扫码-到站
			let level = uni.getStorageSync(this.preutils.accountLevel);
			var isUpload = false;
			if (this.in_type == '2' || this.in_type == '21') {
				if (level == 2) {
					isUpload = false;
				} else if (level == 1) {
					if (this.waybillDetail.status_p2 == 200) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else {
					if (this.waybillDetail.status == 400) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				}
			} else if (this.in_type == '3' || this.in_type == '4') {
				if (level == 2) {
					isUpload = false;
				} else if (level == 1) {
					if (this.waybillDetail.status_p2 == 200) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				} else {
					if (this.waybillDetail.status == 400) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				}
			} else {
				isUpload = false;
			}
			return isUpload;
		},
		showAllocationBtn() { //in_type 1发货或分拨 2到站  11扫码-发货或分拨 21扫码-到站
			let level = uni.getStorageSync(this.preutils.accountLevel);
			var isUpload = false;
			if (this.in_type == '1' || this.in_type == '11') {
				if (level == 2) {
					isUpload = false;
				} else if (level == 1) {
					isUpload = false;
				} else {
					if (this.waybillDetail.status == 500) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				}
			} else if (this.in_type == '3' || this.in_type == '4') {
				if (level == 2) {
					isUpload = false;
				} else if (level == 1) {
					isUpload = false;
				} else {
					if (this.waybillDetail.status == 500) {
						isUpload = true;
					} else {
						isUpload = false;
					}
				}
			} else {
				isUpload = false;
			}
			return isUpload;
		},
		getOrderAmountPay(row) {
			return listStatus.getOrderAmountPay(row);
		},
		getReceiptType(row) {
			return listStatus.getReceiptType(row);
		},
		getIsUrgency(row) {
			return listStatus.getIsUrgency(row);
		},
		getIsControl(row) {
			return listStatus.getIsControl(row);
		},
		getIsUnusual(row) {
			return listStatus.getIsUnusual(row);
		},

		getSelect(row) {
			let d = listStatus.getSelect(row);
			console.log(d)
			return d;
		},
		waybillStatus(rows) {
			return listStatus.status(rows);
		},
		getStatusP2(rows) {
			return listStatus.getStatusP2(rows);
		},
		getLevel(rows) {
			return listStatus.getLevel(rows);
		},
		getStatus(rows) {
			return listStatus.getStatus(rows);
		},
		getTransitStatus(rows) {
			return listStatus.getTransitStatus(rows);
		},
		getDestinationCity(rows) {
			return listStatus.getDestinationCity(rows);
		},
		getDisabledDel(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDisabledEdit(rows) {
			return listStatus.getDisabledEdit(rows);
		},
		getDepartPic1(rows) {
			return listStatus.getDepartPic1(rows);
		},
		getDepartPic2(rows) {
			return listStatus.getDepartPic2(rows);
		},
		getArrivePic1(rows) {
			return listStatus.getArrivePic1(rows);
		},
		getAllocatePic1(rows) {
			return listStatus.getAllocatePic1(rows);
		},
		getAllocatePic2(rows) {
			return listStatus.getAllocatePic2(rows);
		},


		getDepartPic2List(rows) { //二级发车 
			return listStatus.getDepartPic2List(rows);
		},
		getArrivePic1List(rows) { //一级到车  
			return listStatus.getArrivePic1List(rows);
		},
		getDepartPic1List(rows) { //一级发车
			return listStatus.getDepartPic1List(rows);
		},
		getAllocatePic1List(rows) { //分拨中心到车  
			return listStatus.getAllocatePic1List(rows);
		},
		getAllocatePic2List(rows) { //分拨中心分拨 
			return listStatus.getAllocatePic2List(rows);
		},
		imagePicClick(type, row) {
			var list = [];
			switch (type) {
				case 'departPic2': {
					list = this.getDepartPic2List(this.waybillDetail);
					break;
				}
				case 'arrivePic1': {
					list = this.getArrivePic1List(this.waybillDetail);
					break;
				}
				case 'departPic1': {
					list = this.getDepartPic1List(this.waybillDetail);
					break;
				}
				case 'allocatePic1': {
					list = this.getAllocatePic1List(this.waybillDetail);
					break;
				}
				case 'allocatePic2': {
					list = this.getAllocatePic2List(this.waybillDetail);
					break;
				}
			}
			this.showPreviewImage(row, list);
		},

		showPreviewImage(index, ianges) {
			// 预览图片
			uni.previewImage({
				urls: ianges,
				current: index,
				longPressActions: {
					success: function(data) {

					},
					fail: function(err) {

					}
				}
			});
		},

		handleDepart() {
			this.$util.redirectTo('/pages/order/order-confirm/order-depart-confirm', this.waybillDetail, null, 'obj');
		},
		handleDelivery() {
			this.$util.redirectTo('/pages/order/order-confirm/order-arrive-confirm', this.waybillDetail, null, 'obj');
		},
		handleAllocation() {
			this.$util.redirectTo('/pages/order/order-confirm/order-depart-confirm', this.waybillDetail, null, 'obj');
		},
		getDetailData() {
			this.http.sendRequest({
				api: this.api.order.waybillDetailApi,
				data: {
					waybill_id: this.waybill_id
				},
				success: res => {
					if (res.code == '1' && res.data) {
						this.waybillDetail = res.data
						this.showAlertUI();
					}
				},
				fail: res => {
					console.log(res, '==fail')
				}
			});
		},

		confirm() {
			var data = {
				...this.inputData,
			};
			this.http.sendRequest({
				api: this.api.order.sOrderUpdateApi,
				data: data,
				success: res => {
					if (res.code == 1) {
						this.$util.showToast({
							title: res.msg
						});
					}

					this.$util.redirectTo('/pages/tabBar/order/order', {}, 'redirectTo');
				},
				fail: res => {
					console.log(res, '==fail')
				}
			});
		}
	}

}